Data External Export
The dReveal grid component provides methods to export its data to a file or stream in RawData and XLSX format. These methods are available on the server side.
Server Side Export
The methods provided by the grid component on the server side are detailed below:
Name | Return | Format |
---|---|---|
ExportToXlsxXLOnStreamResult | FileStreamResult | RawData |
ExportToXlsxXLOnStreamResult | FileStreamResult | XLSX |
These methods are located in the
Utils
class from the namespaceInfoArch.Web.Mvc.Grid
.
It is important to mention that exists some properties in the GridSettings
object located into the GridViewModel
class, for customizing the Excel exportation. These properties are detailed below:
Property | Description |
---|---|
GridSettings.CustomFileName | Excel file name |
GridSettings.CustomTitle | The title of the report in the Excel file |
Controller
The following code demonstrates how to implement the methods in a controller class:
[HttpGet]
public FileStreamResult ExportExcelGrid()
{
// Create GridViewModel
GridViewModel viewModel = GetGridViewModel();
viewModel.LoadInitialConfiguration();
// Set config in GridSettings
viewModel.GridSettings.CustomFileName = "MyExcelGrid";
viewModel.GridSettings.CustomTitle = "Title Grid";
// If value is FALSE, this line is optional
viewModel.SetXLExportModeOnlyData(false);
// Export Excel
return GridExtension.ExportToXlsxXLOnStreamResult(viewModel);
}
[HttpGet]
public FileStreamResult ExportRawDataGrid()
{
// Create GridViewModel
GridViewModel viewModel = GetGridViewModel();
viewModel.LoadInitialConfiguration();
viewModel.SetXLExportModeOnlyData(true);
// Set config in GridSettings
viewModel.GridSettings.CustomFileName = "MyRawDataGrid";
viewModel.GridSettings.CustomTitle = "Title Grid";
// Export Excel
return GridExtension.ExportToXlsxXLOnStreamResult(viewModel);
}
private GridViewModel GetGridViewModel()
{
return new GridViewModel(
memoryStream: fileStream,
connectionString: "Data Source=MyServer; Initial Catalog=myDatabase; User ID=myUser; Password=myPassword",
gridId: "grid_id",
htmlFormId: "main_form",
rowsPerPage: 15,
enableColumnFinderFeature: true,
isGridPagerSimpleMode: true,
fullGridControllerActionPath: HttpContext.Request.Url.AbsolutePath,
gridActionName: string.Empty,
drillThroughControllerAction: string.Empty,
saveGridControllerAction: string.Empty,
exportToExcelGridControllerAction: string.Empty
);
}
Client Side Export
The following code demonstrates how to call to the server side methods:
<div>
<a href="@Url.Action("ExportExcelGrid", "MyController")">Export EXCEL</a>
<a href="@Url.Action("ExportRawDataGrid", "MyController")">Export RAW DATA</a>
</div>